package com.jinzhi.jzweb.controller;


import java.util.*;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.FormProcessDO;
import com.jinzhi.jzweb.service.FormProcessService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2021-04-01 10:02:51 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/formProcess")
public class FormProcessController extends BaseController {
	@Autowired
	private FormProcessService formProcessService;
	
	@GetMapping()
	@RequiresPermissions("jzweb:formProcess:formProcess")
	String FormProcess(){
	    return "jzweb/formProcess/formProcess";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:formProcess:formProcess")
	public Result<Page<FormProcessDO>> list(FormProcessDO formProcessDTO){
		// 查询列表数据
		Page<FormProcessDO> page = formProcessService.selectPage(getPage(FormProcessDO.class),
					formProcessService.convertToEntityWrapper().orderBy("id", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				FormProcessDO obj = (FormProcessDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:formProcess:add")
	String add(){
	    return "jzweb/formProcess/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:formProcess:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		FormProcessDO formProcess = formProcessService.selectById(id);
		model.addAttribute("formProcess", formProcess);
	    return "jzweb/formProcess/edit";
	}
	
	@Log("添加")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:formProcess:add")
	public Result<String> save( FormProcessDO formProcess){
		formProcessService.insert(formProcess);
        return Result.ok();
	}
	
	@Log("修改")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:formProcess:edit")
	public Result<String>  update( FormProcessDO formProcess){
		boolean update = formProcessService.updateById(formProcess);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:formProcess:remove")
	public Result<String>  remove( Integer id){
		formProcessService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:formProcess:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] ids){
		formProcessService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
